package opensocial4gwt;

public class OpenSocial {
	public static enum CreateActivityPriority {
		HIGH, LOW
	}

	public static native Activity newActivity() /*-{
		return $wnd.opensocial.newActivity();
	}-*/;
	
	public static native MediaItem newMediaItem() /*-{
		return $wnd.opensocial.newMediaItem();
	}-*/;
	
	public static MediaItem newMediaItem(String url, MediaItem.Type type, String mimeType) {
		MediaItem m = newMediaItem();
		m.setURL(url);
		m.setType(type);
		m.setMimeType(mimeType);
		return m;
	}

	public static void requestCreateActivity(Activity activity, CreateActivityPriority priority,
			Callback<ResponseItem> callback) {
		if (priority == null)
			throw new NullPointerException(
					"CreateActivityPriority param in OpenSocial.requestCreateActivity cannot be null.");

		requestCreateActivity(activity, priority.name(), callback);
	}

	private native static void requestCreateActivity(Activity activity, String priority, Callback<ResponseItem> callback) /*-{
		$wnd.opensocial.requestCreateActivity(activity, $wnd.opensocial.CreateActivityPriority[priority], function(response) {
			if (callback)
				callback.@opensocial4gwt.Callback::onSuccess(Ljava/lang/Object;)(response);
		});
	}-*/;

	public native static void log(Object o) /*-{
		$wnd.myLog = o;
		if ($wnd.console)
			$wnd.console.log(o);
		else {
			if (0 == null)
				$wnd.alert(null);
			else
				$wnd.alert(o.toString());
		}
	}-*/;
}
